// JScript 文件
var hideDiv = function(idName){
	$("#"+idName).fadeOut("fast");
};

//是否显示上传后的图片
var isshowpic = true;  
var uploadshowpic = function(el){
    isshowpic = !(isshowpic);
    if(isshowpic)
    {
        el.html("图片显示关闭");
    }
    else
    {
        el.html("图片显示开启");
    }
};

//载入中的GIF动画
var loadingUrl = "../_imgs/loading.gif";

//选择文件后的事件,iframe里面调用的
var uploading = function(imgsrc, itemid){
    var el = $("#divUploading"+itemid);
    $("#frmUpload"+itemid).fadeOut("fast");
    el.fadeIn("fast");
    el.html("<img src='"+loadingUrl+"' align='absmiddle' /> uploading ...");
    return el;
};

//上传时程序发生错误时，给提示，并返回上传状态
var uploaderror = function(errMsg){
    alert(errMsg);
    uploadinit();
};

//上传成功后的处理
var uploadsuccess = function(newpath,itemid,filedata,name,filetype){
    var oldvalue = "";
    $("#divUploading"+itemid).fadeOut("fast");
    $("#frmUpload"+itemid).fadeIn("fast");
    oldvalue=$("#txtUploadControl_"+itemid).val();
    
    switch(itemid)
    {
        case "DodownloadFiles":
            $("#txtUploadControl_"+itemid).val(filedata);
            break;
      case "AuthenticateImages":
      	    $("#txtUploadControl_" + itemid).val(filedata);
            break;
        case "ProductImages":
           	$("#txtUploadControl_" + itemid).addfile(filedata);
           	break;
        default:
            $("#txtUploadControl_"+itemid).val(filedata); 
            break;
    }

    if(isshowpic)
    {
        var attachments = "<div class=\"attachmentitems\">"+filetype+"&nbsp;&nbsp;<a href='"+prependOrgName("/"+newpath)+"' title=单击打开文件' target='_blank'>"+name+"</a>&nbsp;&nbsp; <a href='javascript:void(0);' filedata='"+filedata+"' itemid='"+itemid+"' onclick='uploadinit($(this));'>[删除]</a></div>";
        
        switch(itemid)
        {
        	case "DodownloadFiles":
        		attachments = "<div class=\"attachmentitems\">" + filetype + "&nbsp;&nbsp;<a href='" + prependOrgName("/" + newpath) + "' title=单击打开文件' target='_blank'>" + name + "</a><br />注释：&nbsp;<input type=\"text\" style=\"width: 350px;\" name=\"txtAttachmentFileNotes_" + filedata.split("*")[1] + "\" />&nbsp;&nbsp;<a href='javascript:void(0);' filedata='" + filedata + "' itemid='" + itemid + "' onclick='uploadinit($(this));'>[删除]</a></div>";
        		document.getElementById("divDodownloadFilesList_" + itemid).innerHTML = attachments;
        		$("#divProductImagesList_" + itemid).fadeIn("fast");
                break;
            case "AuthenticateImages": 
				attachments = "<div class=\"attachmentitems\">"+filetype+"&nbsp;&nbsp;<a href='"+prependOrgName("/"+newpath)+"' title=单击打开文件' target='_blank'>"+name+"</a><br />注释：&nbsp;<input type=\"text\" style=\"width: 350px;\" name=\"txtAttachmentFileNotes_"+filedata.split("*")[1]+"\" />&nbsp;&nbsp;<a href='javascript:void(0);' filedata='"+filedata+"' itemid='"+itemid+"' onclick='uploadinit($(this));'>[删除]</a></div>";
				document.getElementById("divAuthenticateImagesList_" + itemid).innerHTML = attachments;
				$("#divAuthenticateImagesList_" + itemid).fadeIn("fast");
                break;
            case "ProductImages":
               	attachments = "<div class=\"attachmentitems\">" + filetype + "&nbsp;&nbsp;<a href='" + prependOrgName("/" + newpath) + "' title=单击打开文件' target='_blank'>" + name + "</a><br />注释：&nbsp;<input type=\"text\" style=\"width: 350px;\" name=\"txtAttachmentFileNotes_" + filedata.split("*")[1] + "\" />&nbsp;&nbsp;<a href='javascript:void(0);' filedata='" + filedata + "' itemid='" + itemid + "' onclick='uploadinit($(this));'>[删除]</a></div>";
               	document.getElementById("divProductImagesList_" + itemid).innerHTML += attachments;
               	$("#divProductImagesList_" + itemid).fadeIn("fast");
               	break;
            default:
            	document.getElementById("div" + itemid + "List_" + itemid).innerHTML = attachments;
                $("#div" + itemid + "List_" + itemid).fadeIn("fast");
                break;
        }
    }
}; 

var currentItemID = 0;  //用于存放共有多少个上传控件了
//创建一个上传控件
var uploadcreate = function(el, itemid){
    currentItemID ++;
    
    var strContent = "<div><iframe src=\"../fileitemupload.aspx?itemtypecode="+itemid+"\" id=\"frmUpload"+itemid+"\" frameborder=\"no\" scrolling=\"no\" style=\"width:100%;height:30px;margin:0px;padding:0px;\"></iframe>";
    strContent += "<div id=\"divUploading"+itemid+"\" style=\"display:none;\" ></div>";
    strContent += "<div id=\"divViewList"+itemid+"\" style=\"display:none;\"></div></div>";
    
    el.append(strContent);
};
var uploadformaterror=function(msg,itemid){
    alert(msg);
    $("#ifUpload2").fadeIn("fast");
    $("#divUploadPic").fadeIn("fast");
    $("#divFilesList2").fadeOut("fast");
    $("#uploading2").hide("fast");
    $("#uploadVa_2").val('');
}
    
$.fn.extend({ 
    removefile:function(data){
            var _fileValue=$(this).val().replace("|"+data,"");
            $(this).val(_fileValue);
    },
    addfile:function(data){
            var _fileValue=$(this).val()+"|"+data;
            $(this).val(_fileValue);
    }
})